import time
import hmac
import hashlib
import base64

def generate_xfyun_token(appid: str, api_secret: str, api_key: str) -> str:

    ts = str(int(time.time()))



    signature_origin = api_key + ts

    hmac_obj = hmac.new(api_secret.encode("utf-8"), signature_origin.encode("utf-8"), hashlib.sha256)

    signa = base64.b64encode(hmac_obj.digest()).decode("utf-8")


    token = f"appid={appid},ts={ts},signa={signa}"
    return token


APPID = "0b69f127"
APISecret = "OWU4MzM1NmEzOGJjMWJmNzBkNjkyZGUx"
APIKey = "0420085f95694f308f55d659e4684d73"



token = generate_xfyun_token(APPID, APISecret, APIKey)
print("生成的临时Token：")
print(token)
print(f"\nToken有效期：24小时（{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())} 生成）")
